package cn.lijiguo.concurrency.part1.ch07;

/**
 * TicketWindow
 *
 * @author lijiguo
 * @date 2019/12/6 15:35
 */
public class TicketWindow implements Runnable {

    private volatile int index = 1;

    private static final int MAX = 100;

    private final Object MONITOR = new Object();

    @Override
    public void run() {
        synchronized (MONITOR) {
            while(index <= MAX) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + ":" + index++);
            }
        }
    }
}
